/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.adapter.driving.query.api.repository;

import com.lap.auth.adapter.driving.query.api.ApiViewLogQueryConverter;
import com.lap.auth.adapter.driving.query.api.mapper.ApiViewLogQueryMapper;
import com.lap.auth.adapter.driving.query.api.po.ApiViewLogQueryPo;
import com.lap.auth.application.api.dto.ApiViewLogDto;
import com.lap.auth.application.api.dto.QueryApiViewLogPageQuery;
import com.lap.auth.application.api.repository.ApiViewLogQueryRepository;
import com.lap.framework.common.dto.page.PageResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class ApiViewLogQueryRepositoryImpl implements ApiViewLogQueryRepository {

  private final ApiViewLogQueryConverter apiViewLogQueryConverter;
  private final ApiViewLogQueryMapper apiViewLogQueryMapper;

  @Override
  public PageResponse<ApiViewLogDto> findByConditionPaged(QueryApiViewLogPageQuery query) {
    long count = apiViewLogQueryMapper.countPageByCondition(query);
    if (count == 0L) {
      return PageResponse.ok(count);
    }
    List<ApiViewLogQueryPo> list = apiViewLogQueryMapper.selectPageByCondition(query);
    return PageResponse.ok(apiViewLogQueryConverter.toDtoList(list), count);
  }
}
